<?php
class Index_Data_Index {
	
	private $database;
	
	public function __construct(){
		$this->database = new Core_Driver_MysqlImproved();
	}
	
	public function getData(){
		$this->database->connect();
		$this->database->prepare(
			"
				SELECT 
				*
				FROM 
				page_settings,
				page_meta_values,
				page_content_values
				WHERE
				page_settings.page_name = page_meta_values.page_name
				AND
				page_settings.page_name = page_content_values.page_name
				ORDER
				BY
				page_content_values.page_creation_date
				DESC
				LIMIT
				1
				;
				"
		);
		$this->database->query();
		$article = $this->database->fetch('array');
		$article['comments'] = $this->getComments($article['page_name']);
		return $article;
	}
	
	private function getComments($pageName){
		$this->database->connect();
		$pageName = $this->database->escape($pageName);
		$this->database->prepare(
			"select * from page_comments where page_name = '$pageName';"
		);
		$this->database->query();
		$comments = "";
		while($commentsData = $this->database->fetch('array')){
			$comments = "<h4>".$commentsData['title']."</h4>
					<p><strong><a href=\"".$commentsData['webpage']."\">".$commentsData['nickname']."</a></strong>
					<a href=\"".$commentsData['emaiil']."\">E-mail</a></p>
					<p>".$commentsData['content']."</p>
					";
		} 
	}
}